/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.inv.report.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.inv.report.entity.InvReport;
import com.thinkgem.jeesite.modules.inv.report.service.InvReportService;
import com.thinkgem.jeesite.modules.sys.entity.Office;

/**
 * 分析报告管理功能Controller
 * @author yangh
 * @version 2017-11-23
 */
@Controller
@RequestMapping(value = "${adminPath}/report/invReport")
public class InvReportController extends BaseController {

	@Autowired
	private InvReportService invReportService;
	
	@ModelAttribute("invReport")
	public InvReport get(@RequestParam(required=false) String id) {
		InvReport entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = invReportService.get(id);
		}
		if (entity == null){
			entity = new InvReport();
		}
		return entity;
	}
	
	@RequiresPermissions("report:invReport:view")
	@RequestMapping(value = {"list", ""})
	public String list(InvReport invReport, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<InvReport> page = invReportService.findPage(new Page<InvReport>(request, response), invReport); 
		model.addAttribute("page", page);
		return "inv/report/invReportList";
	}

	@RequiresPermissions("report:invReport:view")
	@RequestMapping(value = "form")
	public String form(InvReport invReport, Model model) {
		model.addAttribute("invReport", invReport);
		return "inv/report/invReportForm";
	}

	@RequiresPermissions("report:invReport:edit")
	@RequestMapping(value = "save")
	public String save(InvReport invReport, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, invReport)){
			return form(invReport, model);
		}
		invReportService.save(invReport);
		addMessage(redirectAttributes, "保存分析报告成功");
		return "redirect:"+Global.getAdminPath()+"/report/invReport/?repage";
	}
	
	@RequiresPermissions("report:invReport:edit")
	@RequestMapping(value = "delete")
	public String delete(InvReport invReport, RedirectAttributes redirectAttributes) {
		invReportService.delete(invReport);
		addMessage(redirectAttributes, "删除分析报告管理成功");
		return "redirect:"+Global.getAdminPath()+"/report/invReport/?repage";
	}

}